/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import MaDictRadio from "@/components/ma-dict-picker/ma-dict-radio.vue";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import {
  rdDeviceRodOnlineStatusDictData,
  DEFAULT_ONLINE_STATUS,
} from "./common";
import { page as getStandList } from "@/plugins/ai-warning/organization/api/rdOrganizeAreaStand.ts";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  // 设置默认值
  if (formType === "add" && !model.online) {
    model.online = 1;
  }

  return [
    {
      label: "装置名称",
      prop: "name",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "装置名称" }) },
      itemProps: { rules: [{ required: true, message: "请输入装置名称" }] },
    },
    {
      label: "所属站点",
      prop: "stand_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getStandList,
        apiParams: {
          page: 1,
          pageSize: 1000,
        },
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((stand: any) => ({
              label: stand.name,
              value: stand.id,
            }));
          }
          return [];
        },
        placeholder: "请选择所属站点",
        filterable: true,
        clearable: true,
      },
      itemProps: {
        rules: [{ required: true, message: "请选择所属站点" }],
      },
    },
    {
      label: "雷达数量",
      prop: "radar_num",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "雷达数量" }) },
    },
    {
      label: "在线状态",
      prop: "online",
      render: () => MaDictRadio,
      renderProps: {
        multiple: false,
        data: rdDeviceRodOnlineStatusDictData(),
      },
      itemProps: {
        rules: [{ required: true, message: "请选择在线状态" }],
      },
    },
  ];
}
